package com.mushuilingfeng.ddd.user.controller;

import com.mushuilingfeng.ddd.user.bo.UpdatePasswordBO;
import com.mushuilingfeng.ddd.user.bo.UserPersonInfoBO;
import com.mushuilingfeng.ddd.user.service.IUserService;
import com.mushuilingfeng.ddd.user.vo.UserVO;
import com.mushuilingfeng.spring.common.BaseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 沐水淋风
 * @date 2024/9/14
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
@Tag(name = "用户个人中心")
public class UserController {
    private final IUserService userService;
    
    @PostMapping("/logout")
    @Operation(description = "退出登录")
    public BaseResult<Void> logout() {
        userService.logout();
        return BaseResult.success(null);
    }
    
    @PostMapping("/updatePassword")
    @Operation(description = "修改密码")
    public BaseResult<Void> updatePassword(@Valid @RequestBody UpdatePasswordBO bo) {
        userService.updatePassword(bo);
        return BaseResult.success(null);
    }
    
    @GetMapping("/myInfo")
    @Operation(description = "获取用户信息")
    public BaseResult<UserVO> myInfo() {
        return BaseResult.success(userService.myInfo());
    }
    
    @PostMapping("/updateNickName")
    @Operation(description = "修改昵称")
    public BaseResult<Void> updateNickName(@RequestParam String nickName) {
        userService.updateNickName(nickName);
        return BaseResult.success(null);
    }
    
    @PostMapping("/updatePersonInfo")
    @Operation(description = "修改个人信息")
    public BaseResult<Void> updatePersonInfo(@RequestBody UserPersonInfoBO bo) {
        userService.updatePersonInfo(bo);
        return BaseResult.success(null);
    }
    
    
}
